#!/bin/sh

#
# from: Robin Eklund (robin.eklund[located]ki.se)
#

#JVM setup
if [ "x$JAVA" = "x" ]; then
	if [ "x$JAVA_HOME" != "x" ]; then
		JAVA="$JAVA_HOME/bin/java"
	else
		JAVA="java"
	fi
fi
#TMP path
TMP="/tmp"
#Setup basedir
if [ "x$2" = "x" ]; then
	SCHEMA_BASE_DIR=`pwd`
else
	SCHEMA_BASE_DIR=$2
fi
#Version specifier
if [ "x$3" = "x" ]; then
	SCHEMA_VERSION="1.0"
else
	SCHEMA_VERSION=$3
fi
#Jars
XALAN_JARS="java/endorsed/serializer-2.7.1.jar:java/endorsed/xalan-2.7.1.jar:java/endorsed/xercesImpl-2.7.1.jar:java/endorsed/xml-apis-2.7.1.jar"
#And run
echo "---"
"$JAVA" -Xbootclasspath/a:$XALAN_JARS -cp java/classes org.apache.xalan.xslt.Process -XSL test-suite.xslt -PARAM basedir "$1" -PARAM schemas-basedir-param "$SCHEMA_BASE_DIR" -PARAM schema-version-param "$SCHEMA_VERSION" > $TMP/test-results.xml 
echo "---"
"$JAVA" -Xbootclasspath/a:$XALAN_JARS org.apache.xalan.xslt.Process -XSL format/test-result.xslt -IN $TMP/test-results.xml -OUT $TMP/test-results.html
echo "---"
#Deb-style browser call
sensible-browser $TMP/test-results.html
